﻿using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;

namespace ECommon
{
    /// <summary>
    /// 硬件工具类
    /// </summary>
    public static partial class HardwareTool
    {
        /// <summary>
        /// 获取ipv4地址
        /// </summary>
        /// <returns>ipv4地址</returns>
        public static List<string> GetIpV4Address()
        {
            //获取当前的ip地址
            IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
            List<string> ipList = new List<string>();
            // 遍历所有的IP地址
            foreach (IPAddress ip in host.AddressList)
            {
                if (ip.AddressFamily == AddressFamily.InterNetwork) // IPv4地址
                {
                    ipList.Add(ip.ToString());
                }
            }
            return ipList;
        }
    }
}
